{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from scipy.io import loadmat\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('/media/taufiq/Data/heart_sound/Heart_Sound/Physionet/2016-07-25_Updated files for Challenge 2016/Online Appendix_training set.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "mask1= df['Class (-1=normal 1=abnormal)']==1\n",
    "mask2= df['Database']=='training-e'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "recordinglist = df['Challenge record name'][mask1][mask2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n"
     ]
    }
   ],
   "source": [
    "springerpath= \"/media/taufiq/Data/heart_sound/Heart_Sound/Physionet/2016-07-25_Updated files for Challenge 2016/20160725_automated David Springer's annotations for training set/training-e-Aut/\"\n",
    "groundpath= \"/media/taufiq/Data/heart_sound/Heart_Sound/Physionet/2016-07-25_Updated files for Challenge 2016/20160725_hand corrected annotations for training set/training-e_StateAns/\"\n",
    "sum =0\n",
    "for name in recordinglist:\n",
    "    filename = name+\"_StateAns0.mat\"\n",
    "    sprin = loadmat(springerpath+filename)\n",
    "    filename = name+'_StateAns.mat'\n",
    "    anno = loadmat(groundpath+filename)\n",
    "    if len(anno['state_ans'][:,0])==2:\n",
    "        continue\n",
    "    sum= sum + abs(len(anno['state_ans'][:,0])-len(sprin['state_ans0'][:,0]))\n",
    "print sum/len(recordinglist)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
